#!/bin/bash

echo "Type your User Name, followed by [ENTER]:"
read user_name

echo "Type your Web Server User Name, followed by [ENTER]:"
read server_name

if [ -f upload/config.php ]
  then
    mv upload/config.php upload/config_backup.php
fi

if [ -f upload/admin/config.php ]
  then
    mv upload/admin/config.php upload/admin/config_backup.php
fi

if [ "$(ls -A upload/system/logs/)" ]
   then
    rm upload/system/logs/*
    cat /dev/null > upload/system/logs/index.html
fi

if [ "$(ls -A upload/system/cache/)" ]
   then
      rm upload/system/cache/*
      cat /dev/null > upload/system/cache/index.html
fi

find ./ -name '*~' | xargs rm

cat /dev/null > upload/config.php
cat /dev/null > upload/admin/config.php

sudo chown $user_name:$server_name upload/config.php
sudo chown $user_name:$server_name upload/admin/config.php

sudo chown -R $user_name:$server_name upload/system/config/
sudo chown -R $user_name:$server_name upload/system/cache/
sudo chown $user_name:$server_name upload/system/logs/

sudo chown $user_name:$server_name upload/image/
sudo chown -R $user_name:$server_name upload/image/cache/
sudo chown -R $user_name:$server_name upload/image/data/
sudo chown -R $user_name:$server_name upload/download/

sudo chmod 774 upload/config.php
sudo chmod 774 upload/admin/config.php
sudo chmod -R 774 upload/system/config/
sudo chmod 774 upload/system/cache/
sudo chmod 774 upload/system/logs/
sudo chmod 774 upload/image/
sudo chmod -R 774 upload/image/cache/
sudo chmod -R 774 upload/image/data/
sudo chmod 774 upload/download/

exit 0;
